package com.igeek.ch02.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * @author
 * 2023/7/26 15:53
 * @description 编码集过滤器
 */
@WebFilter(filterName = "f1" , urlPatterns = "/*")
public class EncodeFilter implements Filter {

    //初始化
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    //过滤
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        servletRequest.setCharacterEncoding("UTF-8");
        servletResponse.setCharacterEncoding("UTF-8");
        //servletResponse.setContentType("text/html;charset=UTF-8");

        //过滤链
        filterChain.doFilter(servletRequest, servletResponse);
    }

    //销毁
    @Override
    public void destroy() {

    }
}
